package com.xiaohong.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.order.dao.OrderItemMapper;
import com.xiaohong.order.pojo.OrderItem;
import com.xiaohong.order.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderItemServiceImpl implements OrderItemService {

    @Autowired
    private OrderItemMapper orderItemMapper;


    /**
     * 条件+分页查询OrderItem
     * @param orderItem 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<OrderItem> findPage(OrderItem orderItem, int page, int size){
        // 构建查询条件
        QueryWrapper<OrderItem> queryWrapper = new QueryWrapper<OrderItem>(orderItem);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return orderItemMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询OrderItem
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<OrderItem> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return orderItemMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法OrderItem
     * @param orderItem
     * @return
     */
    @Override
    public List<OrderItem> findList(OrderItem orderItem){
        // 构建查询条件
        QueryWrapper<OrderItem> queryWrapper = new QueryWrapper<OrderItem>(orderItem);
        // 查询数据
        return orderItemMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除OrderItem
     * @param id
     */
    @Override
    public void delete(String id){
        orderItemMapper.deleteById(id);
    }

    /**
     * 根据ID修改OrderItem
     * @param orderItem
     */
    @Override
    public void update(OrderItem orderItem){
        orderItemMapper.updateById(orderItem);
    }

    /**
     * 增加OrderItem
     * @param orderItem
     */
    @Override
    public void add(OrderItem orderItem){
        orderItemMapper.insert(orderItem);
    }

    /**
     * 根据ID查询OrderItem
     * @param id
     * @return
     */
    @Override
    public OrderItem findById(String id){
        return  orderItemMapper.selectById(id);
    }

    /**
     * 查询全部OrderItem数据
     * @return
     */
    @Override
    public List<OrderItem> findAll() {
        return orderItemMapper.selectList(null);
    }
}
